home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!insosf1.netins.net
- From: Alan Jones <alan.jones@qcs.org>
- Newsgroups: comp.sys.cbm
- Subject: Re: C= FP arithmetic
- Date: Sun, 18 Feb 1996 11:28:00 GMT
- Organization: Quad-cities Computer Society
- Message-ID: <96021817503147288@qcs.org>
- X-NNTP-Posting-Host: insosf1.netins.net
- X-Mail2News-Path: insosf1.netins.net
-
-
- ddeter T Karlsson <dat95pkn@idt.mdh.se> wrote:
- >>C=64+64*INT(.1+.9)
- >>will give C 64 for a C64 and 128 on a C128!
-
- >I find this very interesting. Does anyone have an explanation for
- this?
-
- Craig Bruce replied:
-
- Floating-point arithmetic is a bit of a crap shoot anyway. Maybe they
- subtly changed the addition code between the two versions, or...
-
- I have some vague notions about the floating-point accumulators (FACs)
- storing a number with slightly more precision than a floating-point
- variable, so this may be what is happening. If the number doesn't have
-
- to leave the FACs (which it doesn't in the above first example), then
- there may be a slightly different answer from if it does. Maybe the
- C128 stores or doesn't store intermediate results from the FACs while
- the C64 doesn't/does.
-
-
- I must disagree with Craig, but then I admit that I don't know enough
- about crap shooting. ;)
-
- I too find this interesting. I have not read much about our BASIC 7.0
- other than additional commands. I don't know what the 128 does
- differently from the C64 here. I am not surprised that INT(.9+.1) = 0
- on a C64. I note that INT(9/10+1/10) produces the same poor result
- while avoiding the input conversion problem. Actually I do all my
- numerical work using COMAL 2.0 on a C64 (or 128 in C64 mode at 2MHz).
- So far as I know, COMAL uses the same FP kernel FP arithmetic routines,
- although SQR (square root) was improved.
-
- In COMAL at least, five byte floating point mumbers are fetched from
- memory and placed on the stack in a 6 byte form. One byte is used to
- hold the sign and four bytes are used to hold the unsigned mantissa.
- In all cases proper rounding FP arithmetic is used, assuming you use
- the kernel FP routines. I use a ML level 1 BLAS package with COMAL
- 2.0. This calls the kernel math routines, but it is MUCH faster
- because it takes array indexing and other overhead out of the hands of
- the interpreter. The interesting thing is that sometimes calculations
- made using the BLAS differ from the equivalent in-line code. Because a
- partial sum can be kept on the stack, it sometimes behaves as a gaurd
- digit in the calculation. When the results using the BLAS are
- different they can be considerred more accurate, even though the same
- FP arithmetic routines are used. :)
-
- BTW, in COMAL 2.0 on a 128D in C64 mode, print int(.9+.1) is 1 :)
- If anyone is serious about doing "heavy math" on a C64 I strongly
- recommend the Comal programming language.
-
- Someone recommeded using FP variables to hold integers. Unfortunately,
- this only gives you 9 decimal digits before roundoff error creeps in.
- There are how many digits in the national debt?!!!!
-
- There is nothing wrong with using BCD arithmetic. Some of the most
- accurate numerical codes use BCD arithmetic. One can find software for
- Interval Arithmetic and extremely high precision calculations (like
- calculating PI to bazillions of digits) using BCD arithmetic.
-
- To be sure, FP arithmetic can produce some surprising results (at least
- for the unwary). For example, it is an algebraic fact that a*b = b*a.
- But this in not always true of all FP arithmetics.
-
- alan.jones@qcs.org
-
- ___ QWKRR128 V4.32 [R]
-